package com.euq.utils;

import com.euq.dto.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtils {
    public static LoginUser getCurrentUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication == null) {
            throw new RuntimeException("当前未认证用户");
        }
        return (LoginUser) authentication.getPrincipal();
    }

    public static String getUsername() {
        return getCurrentUser().getUsername();
    }
}
